const path = require('path');
const express = require('express');
const logger = require('morgan');
const nunjucks = require('nunjucks');

const studentRouter = require('./routes/student');

const port = 3000;
const app = express();

// 指定模板文件所在的根目录
const templateRoot = path.resolve(__dirname,'pages');
// 设置模板文件所在的目录 (即确定寻找模板文件时的路径)
app.set( 'views' , templateRoot );
// 设置模板文件的扩展名 (即确定寻找那种扩展名的文件)
app.set( 'view engine' , 'njk' );

// 设置 nunjucks 模板引擎 ( 一定要将 app 传递进去 ) 
nunjucks.configure( templateRoot ,{ autoescape: true, express: app })

app.use(logger('dev'));
app.use(express.text());
app.use(express.json());
app.use(express.urlencoded({extended: false}));
app.use(express.static( path.resolve(__dirname,'assets') ));

app.use(studentRouter);

app.listen(port,() => console.log(`正在监听${port}端口`) );